<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>二进制安全比较字符串（不区分大小写）</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="function.str-word-count.html">« str_word_count</a></li>
      <li style="float: right;"><a href="function.strchr.html">strchr »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="ref.strings.html">字符串 函数</a></li>
    <li>二进制安全比较字符串（不区分大小写）</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="function.strcasecmp" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">strcasecmp</h1>
  <p class="verinfo">(PHP 4, PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">strcasecmp</span> &mdash; <span class="dc-title">二进制安全比较字符串（不区分大小写）</span></p>

 </div>
 
 <div class="refsect1 description" id="refsect1-function.strcasecmp-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>strcasecmp</strong></span>(<span class="methodparam"><span class="type">string</span> <code class="parameter">$string1</code></span>, <span class="methodparam"><span class="type">string</span> <code class="parameter">$string2</code></span>): <span class="type">int</span></div>

  <p class="para rdfs-comment">
   二进制安全比较字符串（不区分大小写）。比较不会注意区域；只有 ASCII 字母以不区分大小写的方式进行比较。
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.strcasecmp-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>
    
     <dt>
<code class="parameter">string1</code></dt>

     <dd>

      <p class="para">
       第一个字符串
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">string2</code></dt>

     <dd>

      <p class="para">
       第二个字符串
      </p>
     </dd>

    
   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.strcasecmp-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   如果 <code class="parameter">string1</code> 小于 <code class="parameter">string2</code> 返回
   <code class="literal">-1</code>；如果 <code class="parameter">string1</code> 大于 <code class="parameter">string2</code>
   返回 <code class="literal">1</code>；如果两者相等，返回 <code class="literal">0</code>。
  </p>
 </div>


 <div class="refsect1 changelog" id="refsect1-function.strcasecmp-changelog">
  <h3 class="title">更新日志</h3>
  <table class="doctable informaltable">
   
    <thead>
     <tr>
      <th>版本</th>
      <th>说明</th>
     </tr>

    </thead>

    <tbody class="tbody">
     <tr>
 <td>8.2.0</td>
 <td>
  现在此函数返回 <code class="literal">-1</code> 或者 <code class="literal">1</code>，之前返回负数或正数。
 </td>
</tr>


    </tbody>
   
  </table>

 </div>


 <div class="refsect1 examples" id="refsect1-function.strcasecmp-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-4835">
    <p><strong>示例 #1 <span class="function"><strong>strcasecmp()</strong></span> 范例</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$var1&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">"Hello"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$var2&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">"hello"</span><span style="color: #007700">;<br />if&nbsp;(</span><span style="color: #0000BB">strcasecmp</span><span style="color: #007700">(</span><span style="color: #0000BB">$var1</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$var2</span><span style="color: #007700">)&nbsp;==&nbsp;</span><span style="color: #0000BB">0</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">'$var1&nbsp;is&nbsp;equal&nbsp;to&nbsp;$var2&nbsp;in&nbsp;a&nbsp;case-insensitive&nbsp;string&nbsp;comparison'</span><span style="color: #007700">;<br />}<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

   </div>   
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.strcasecmp-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="function"><a href="function.strcmp.html" class="function" rel="rdfs-seeAlso">strcmp()</a> - 二进制安全字符串比较</span></li>
    <li class="member"><span class="function"><a href="function.preg-match.html" class="function" rel="rdfs-seeAlso">preg_match()</a> - 执行匹配正则表达式</span></li>
    <li class="member"><span class="function"><a href="function.substr-compare.html" class="function" rel="rdfs-seeAlso">substr_compare()</a> - 二进制安全比较字符串（从偏移位置比较指定长度）</span></li>
    <li class="member"><span class="function"><a href="function.strncasecmp.html" class="function" rel="rdfs-seeAlso">strncasecmp()</a> - 二进制安全比较字符串开头的若干个字符（不区分大小写）</span></li>
    <li class="member"><span class="function"><a href="function.stristr.html" class="function" rel="rdfs-seeAlso">stristr()</a> - strstr 函数的忽略大小写版本</span></li>
    <li class="member"><span class="function"><a href="function.substr.html" class="function" rel="rdfs-seeAlso">substr()</a> - 返回字符串的子串</span></li>
   </ul>
  </p>
 </div>


</div></div></div></body></html>